z = int(input())
m = 0
if len(str(z)) == 4:
    for i in range(2, z // 2 + 1):
        if z % i == 0:
            break
    else:
        m = z
    h = str(z)
    for i in range(len(h)):
        for j in range(i+1, len(h)+1):
            if i == 0 and h[i] == '0':
                continue
            u = int(h[i:j])
            for k in range(2, u):
                if u % k == 0:
                    break
            else:
                if u > m:
                    m = u

print(m)
